package org.bbl.web;

import com.google.inject.Binder;
import com.google.inject.Module;
import org.apache.wicket.Page;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.RuntimeConfigurationType;
import org.apache.wicket.Session;
import org.apache.wicket.authroles.authorization.strategies.role.IRoleCheckingStrategy;
import org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.guice.GuiceComponentInjector;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.Response;
import org.apache.wicket.settings.ISecuritySettings;
import org.apache.wicket.util.crypt.ClassCryptFactory;
import org.apache.wicket.util.crypt.NoCrypt;
import org.bbl.startup.BblConfiguration;

/**
 * @author biniam.gebremichael
 * @since 4/4/13
 */
public class WicketApplication extends WebApplication {

    @Override
    public Class<? extends Page> getHomePage() {
        return HomePage.class;
    }

    @Override
    public Session newSession(Request request, Response response) {
        return super.newSession(request, response);
    }

    @Override
    protected void init() {
        getComponentInstantiationListeners().add(new GuiceComponentInjector(this, BblConfiguration.getModules()));
        getSecuritySettings().setCryptFactory(
                new ClassCryptFactory(NoCrypt.class, ISecuritySettings.DEFAULT_ENCRYPTION_KEY));
        getSecuritySettings().setAuthorizationStrategy(
                new RoleAuthorizationStrategy(new IRoleCheckingStrategy() {
                    @Override
                    public boolean hasAnyRole(Roles strings) {
                        return true;
                    }
                }));
       getDebugSettings().setAjaxDebugModeEnabled(false);
    }

    @Override
    public RuntimeConfigurationType getConfigurationType() {
        return RuntimeConfigurationType.DEPLOYMENT;
    }
}
